const Prize = require("./../model/Prize");

exports.getPrizeCountByName = (req, res) => {
  const { name } = req.query;
  Prize.find({ name })
    .select("count name")
    .exec((err, result) => {
      if (err) {
        return res.send({ code: 500, message: "error" });
      }
      if (result) {
        return res.send({ code: 200, data: result });
      } else {
        return res.send({ code: 200, data: [] });
      }
    });
};

exports.addPrize = (req, res) => {
  const { count, name } = req.body;
  const prize = new Prize({ name, count });
  prize.save((err) => {
    if (err) {
      return res.send({ code: 500, message: "error" });
    }
    return res.send({ code: 200, message: "success" });
  });
};
